var ws,order_id,logistics_num,logistics_company;
var app = angular.module('app',[]);
app.controller('my_controller',function($scope,$http){
	$scope.intview = function(){
		plus.nativeUI.showWaiting('加载中...')
		$http({
			method:'post',
			url:apiRoot,
			data:{
				action:'Logistics.getExpressCompanyInfo'
			}
		}).then(function success(result){
			plus.nativeUI.closeWaiting();
			$scope.res = result.data.data; 
		},function errorFunction(e){
			plus.nativeUI.closeWaiting();
			plus.closeWaiting();
			console.log(JSON.stringify(e));
		})
	}
	
	
	
	$scope.deliverGoods = function(){		
		logistics_company = $('input[type=radio]:checked').val();//物流公司
		logistics_num = $('#logistics_num').val();	//物流单号	
		
		//判断物流公司是否选择
		if(logistics_company == ''){
			mui.toast("请选择物流公司");return;
		}
		if(logistics_num == ""){
			mui.toast("请填写物流单号");return;
		}else{
			if(!logistics_num.match(express)){
				mui.toast("单号只包含数字和字母，请重新输入");return;
			}
		}
		if(logistics_company !="" &&  logistics_num != "" ){
			$('#logistics_btn').attr('disabled',false);
		} else {
			return;
		}
		plus.nativeUI.showWaiting('提交中...');  
		console.log(logistics_company +"++++"+logistics_num);
		$http({
			method:'post',
			url:apiRoot,
			data:{
				action:'Logistics.deliverGoods',
				ddid:order_id,				
				logistics:logistics_company,
				logistics_num:logistics_num
			}
		}).then(function successFunction(result){
			plus.nativeUI.closeWaiting();			
			$scope.res = result.data.data;
			mui.toast("提交成功");
			openNewPage('deliver_goods_control.html');
		},function  errorFunction(e){
			plus.nativeUI.closeWaiting();
			console.log(e)
		})
	}
	
})

document.addEventListener('plusready',function(){
	ws = plus.webview.currentWebview();
	order_id = ws.order_id;
	appElement = document.querySelector('[ng-controller=my_controller]');
	$scope = angular.element(appElement).scope();
	$scope.intview();
	$scope.$apply();
})

